package com.test.jbpm.web.action;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.test.jbpm.Pager;
import com.test.jbpm.domain.TroubleTicket;
import com.test.jbpm.service.TroubleTicketService;


@Controller
@Scope("prototype")
public class MyTroubleTicketAction extends AbtractTroubleTicketAction {

	private TroubleTicketService troubleTicketService;
	
	private TroubleTicket troubleTicket;
	
	private Integer[] troubleTicketIds;
	
	@Autowired
	public void setTroubleTicketService(TroubleTicketService troubleTicketService) {
		this.troubleTicketService = troubleTicketService;
	}

	public TroubleTicket getTroubleTicket() {
		return troubleTicket;
	}

	public void setTroubleTicket(TroubleTicket troubleTicket) {
		this.troubleTicket = troubleTicket;
	}

	public Integer[] getTroubleTicketIds() {
		return troubleTicketIds;
	}

	public void setTroubleTicketIds(Integer[] troubleTicketIds) {
		this.troubleTicketIds = troubleTicketIds;
	}

	public String index() throws Exception {
		return SUCCESS;
	}
	
	public String list() throws Exception {
		Pager<TroubleTicket> pager=null;
		System.out.println(currentUser().getId());
		try {
			pager = troubleTicketService.findMyTroubleTicketList(currentUser().getId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return troubleTicket2JsonString(pager);
	}
	
	public String add() throws Exception {
		//设置建障人
		troubleTicket.setCreator(currentUser());
		troubleTicketService.addOrUpdate(troubleTicket);
		return ajaxOut("{success:true}");
	}
	public String dispatch() throws Exception {
		troubleTicketService.dispatch(troubleTicketIds);
		return ajaxOut();
	}
	public TroubleTicketService getTroubleTicketService() {
		return troubleTicketService;
	}
	
}
